]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appDisplay: Move ensureIconVisible logic to util, make it more generic
authorJasper St. Pierre <jstpierre@mecheye.net>
Mon, 11 Mar 2013 17:43:38 +0000 (13:43 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Tue, 12 Mar 2013 23:29:47 +0000 (19:29 -0400)
In particular, make it work if we have multiple parents, like in the
search case.

https://bugzilla.gnome.org/show_bug.cgi?id=689681

js/misc/util.js
js/ui/appDisplay.js

index d0ea7ca3f4f44420be3eec8fe70f6940046499db..15edc37ef0dc80fb378264d30ba29da176f753e9 100644 (file)
@@ -5,6 +5,9 @@ const GLib = imports.gi.GLib;
 const St = imports.gi.St;
 
 const Main = imports.ui.main;
+const Tweener = imports.ui.tweener;
+
+const SCROLL_TIME = 0.1;
 
 // http://daringfireball.net/2010/07/improved_regex_for_matching_urls
 const _balancedParens = '\\((?:[^\\s()<>]+|(?:\\(?:[^\\s()<>]+\\)))*\\)';
@@ -234,3 +237,39 @@ function makeCloseButton() {
 
     return closeButton;
 }
+
+function ensureActorVisibleInScrollView(scrollView, actor) {
+    let adjustment = scrollView.vscroll.adjustment;
+    let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
+
+    let offset = 0;
+    let vfade = scrollView.get_effect("fade");
+    if (vfade)
+        offset = vfade.vfade_offset;
+
+    let box = actor.get_allocation_box();
+    let y1 = box.y1, y2 = box.y2;
+
+    let parent = actor.get_parent();
+    while (parent != scrollView) {
+        if (!parent)
+            throw new Error("actor not in scroll view");
+
+        let box = parent.get_allocation_box();
+        y1 += box.y1;
+        y2 += box.y1;
+        parent = parent.get_parent();
+    }
+
+    if (y1 < value + offset)
+        value = Math.max(0, y1 - offset);
+    else if (y2 > value + pageSize - offset)
+        value = Math.min(upper, y2 + offset - pageSize);
+    else
+        return;
+
+    Tweener.addTween(adjustment,
+                     { value: value,
+                       time: SCROLL_TIME,
+                       transition: 'easeOutQuad' });
+}
index 1120071c780bf2ad24efd1ba259fdfe9ec14315b..79463b2ad2a5e8fd8546be95ac86903b146b095e 100644 (file)
@@ -29,7 +29,6 @@ const Util = imports.misc.util;
 
 const MAX_APPLICATION_WORK_MILLIS = 75;
 const MENU_POPUP_TIMEOUT = 600;
-const SCROLL_TIME = 0.1;
 const MAX_COLUMNS = 6;
 
 const INACTIVE_GRID_OPACITY = 77;
@@ -259,29 +258,7 @@ const AllView = new Lang.Class({
     },
 
     _ensureIconVisible: function(icon) {
-        let adjustment = this.actor.vscroll.adjustment;
-        let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
-
-        let offset = 0;
-        let vfade = this.actor.get_effect("fade");
-        if (vfade)
-            offset = vfade.vfade_offset;
-
-        // If this gets called as part of a right-click, the actor
-        // will be needs_allocation, and so "icon.y" would return 0
-        let box = icon.get_allocation_box();
-
-        if (box.y1 < value + offset)
-            value = Math.max(0, box.y1 - offset);
-        else if (box.y2 > value + pageSize - offset)
-            value = Math.min(upper, box.y2 + offset - pageSize);
-        else
-            return;
-
-        Tweener.addTween(adjustment,
-                         { value: value,
-                           time: SCROLL_TIME,
-                           transition: 'easeOutQuad' });
+        Util.ensureActorVisibleInScrollView(this.actor, icon);
     },
 
     _updateIconOpacities: function(folderOpen) {